package dissertation.examples.ejb11.entity;

import javax.naming.Context;
import javax.naming.InitialContext;
import java.util.Enumeration;

public class ProductClient {
    public static void main(String[] args) throws Exception {
        Context ctx = new InitialContext(System.getProperties());
        ProductHome productHome = (ProductHome) ctx.lookup("ProductHome");

        //create products
        productHome.create("1", "Lightsaber", 100);
        productHome.create("2", "Donut", 1.59);
        productHome.create("3", "Lightsaber", 120);

        //find products
        Enumeration enumerationList = productHome.findByName("Lightsaber");
        System.out.println("The following products were found:");
        while (enumerationList.hasMoreElements()) {
            Product product = (Product) enumerationList.nextElement();
            System.out.println(product.getName() + " " + product.getPrice());
        }

        //remove product
        Product product = productHome.findByPrimaryKey(new ProductPK("2"));
        product.remove();
    }
}
